package com.huaguoguo.cyg.redis;

import redis.clients.jedis.*;

import java.util.LinkedList;
import java.util.List;

/**
 * 类说明： <br/>
 * author:huaguoguo
 * Date: 2019/8/20
 * Time: 0:07
 */
public class RedisUtils {

    private static ShardedJedisPool pool;
    static {
        JedisPoolConfig config = new JedisPoolConfig();
        config.setMaxTotal(100);
        config.setMaxIdle(50);
        config.setMaxWaitMillis(3000);
        config.setTestOnBorrow(true);
        config.setTestOnReturn(true);
        // 集群
        JedisShardInfo jedisShardInfo1 = new JedisShardInfo("139.9.77.29", 6379);
        jedisShardInfo1.setPassword("123456");
        List<JedisShardInfo> list = new LinkedList<JedisShardInfo>();
        list.add(jedisShardInfo1);
        pool = new ShardedJedisPool(config, list);
    }

    public static ShardedJedis getJedis(){
        return pool.getResource();
    }
}
